package com.wushi.lenovo.asia5b.app_di.credit.presenter;

import com.mvp.base.BasePresenter;
import com.mvp.base.model.ResultModel;
import com.wushi.lenovo.asia5b.app_di.credit.mvpview.TransHisListView;
import com.wushi.lenovo.asia5b.app_http.ApiService;
import com.wushi.lenovo.asia5b.app_model.credit.TopupHisModel;
import com.wushi.lenovo.asia5b.app_model.credit.TransactionHisModel;
import com.wushi.lenovo.asia5b.app_model.credit.TransferHisModel;
import com.wushi.lenovo.asia5b.app_model.credit.WithdrawHisModel;
import com.wushi.lenovo.asia5b.app_model.credit.bean.TransactionHisType;
import com.wushi.lenovo.asia5b.app_model.other.UserInfo;

import java.util.List;

import javax.inject.Inject;

import io.reactivex.Observable;


/**
 * Created by zhangyuncai on 2019/1/21.
 */
public class TransHisListPresenter extends BasePresenter<TransHisListView> {

    ApiService apiService;

    @Inject
    public TransHisListPresenter(ApiService apiService) {
        this.apiService = apiService;
    }

    public void getTransactionHisList(String filter, TransactionHisType type) {
        if (type == TransactionHisType.all) {
            Observable<ResultModel<List<TransactionHisModel>>> observable = apiService.getTransactionHisList(UserInfo.getMemberId(), filter);
            baseSubscribe(observable,
                    listResultModel -> {
                        getView().getTransactionHisListResult(listResultModel, filter);
                    });
        } else if (type == TransactionHisType.topup) {
            Observable<ResultModel<List<TopupHisModel>>> observable = apiService.getTopupHisList(UserInfo.getMemberId(), filter);
            baseSubscribe(observable,
                    listResultModel -> {
                        getView().getTransactionHisListResult(listResultModel, filter);
                    });
        } else if (type == TransactionHisType.withdraw) {
            Observable<ResultModel<List<WithdrawHisModel>>> observable = apiService.getWithdrawHisList(UserInfo.getMemberId(), filter);
            baseSubscribe(observable,
                    listResultModel -> {
                        getView().getTransactionHisListResult(listResultModel, filter);
                    });
        } else if (type == TransactionHisType.credittrans) {
            Observable<ResultModel<List<TransferHisModel>>> observable = apiService.getTransferHisList(UserInfo.getMemberId(), filter);
            baseSubscribe(observable,
                    listResultModel -> {
                        getView().getTransactionHisListResult(listResultModel, filter);
                    });
        }


    }

}